package goiot;

import java.text.FieldPosition;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MySimpleDateFormat extends SimpleDateFormat {

	private static final long serialVersionUID = 1L;

	SimpleDateFormat p1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	SimpleDateFormat p2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

	@Override
	public Date parse(String source) throws ParseException {
		try {
			return p2.parse(source);
		} catch (ParseException e) {
			return p1.parse(source);
		}
	}

	@Override
	public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos) {
		return p1.format(date, toAppendTo, pos);
	}

}
